package com.zbu.regex;

import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexDemo {
    public static void main(String[] args) {
        //QQ正则
//        String telRegex = "[^0]\\d{4,11}";
//        Scanner sc = new Scanner(System.in);
//        System.out.print("QQ号:");
//        String QqNums = "2345678912";
//        System.out.println(QqNums.matches(telRegex));
        //手机号正则
//        String cellRegex = "[1][\\d&&[^120]]\\d{9}";
//        System.out.println("13633333333".matches(cellRegex));

        //邮箱正则
//        String emailRegex = "\\w+[@][\\w&&[^_]]+(\\.[a-z]{2,3})+";
//        System.out.println("zhangSan@itcast.cn".matches(emailRegex));
//        System.out.println("zhangSan@163.com".matches(emailRegex));
//        System.out.println("123456@qq.cn".matches(emailRegex));
//        System.out.println("zhangsan@sina.com".matches(emailRegex));
//        System.out.println("zhangsan@itcast.qq.com".matches(emailRegex));
//        System.out.println("zhangsan@xxx.edu".matches(emailRegex));
//        System.out.println("zhangsan@xxx.org".matches(emailRegex));

        //数据爬取
        String arr = "来学习Java"+
                "电话:18666668888，18699997777或者联系"+
                "邮箱:boniu@itcast.cn 邮箱:bozai@itcast.cn 邮箱2:dlei0009@163.com" +
                "座机电话:01036517895，010-98951256"+
                "热线电话:400-618-9090，400-618-4000，4006184000，4006189090";
        //定义爬去正则
        String telRegex = "1[\\d&&[^120]]\\d{9}|\\w+[@][\\w&&[^_]]+(\\.[a-z]{2,3})+|010-?\\d{8}|400-?\\d{3}-?\\d{4}";
        //将正则表达式封装为一个Pattern对象
        Pattern pattern = Pattern.compile(telRegex);
        //获取匹配器对象
        Matcher matcher = pattern.matcher(arr);
        //通过匹配器，从内容中爬取信息
        while (matcher.find()) {
            System.out.println(matcher.group());
        }

    }
}
